package com.victor.controller.app.hotel_food_happy;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.victor.entity.partner.PartnerUser;
import com.victor.entity.receive.AppGetFoodEntity;
import com.victor.entity.receive.AppGetHappyEntity;
import com.victor.entity.receive.AppGetHotelEntity;
import com.victor.service.PartnerService;
import com.victor.utils.LocationUtils;
import com.victor.utils.Msg;

@RestController
@RequestMapping("/partner_app")
public class PartnerAppController {

	@Autowired
	private PartnerService partnerService;

	/** 宾馆 */
	// 获取商户类别PartnerController --- getPartnerType(t_type) 商家类型(1.宾馆 2.美食 3.娱乐)

	// 查询宾馆列表
	/*
	 * -- t_id 商户类别表id -- position_city 市搜索 -- position_area 区搜索 -- h_price_start
	 * 价钱搜索开始价格 -- h_price_end 价钱搜索结束价格 -- h_star 星级搜索 -- search 搜索内容
	 */
	@RequestMapping("/appGetHotelList")
	public Msg appGetHotelList(AppGetHotelEntity appGetHotelList) {
		PageHelper.startPage(appGetHotelList.getPage(), appGetHotelList.getRow());
		List<PartnerUser> partnerUsers = partnerService.appGetHotelList(appGetHotelList);
		if (partnerUsers != null && partnerUsers.size() > 0) {
			for (PartnerUser partnerUser : partnerUsers) {
				partnerUser.setJuli(LocationUtils.getDistance(appGetHotelList.getUserlon(), appGetHotelList.getUserlat(), partnerUser.getPosition_lon(), partnerUser.getPosition_lat()));
			}
		}
		return Msg.success().add("partnerUsers", new PageInfo<>(partnerUsers, 5));
	}

	// 获取商家详情PartnerController --- getPartnerUserXQ(partnerUserid)

	// 获取房间详情PartnerController --- getHotelRoomXQ(r_id)

	// 获取推荐宾馆--3个
	@RequestMapping("/appGetHotelTuijian")
	public Msg appGetHotelTuijian(String position_city) {
		List<PartnerUser> partnerUsers = partnerService.appGetTuijian(position_city, "1");// (1.酒店.2.美食. 3娱乐)
		return Msg.success().add("partnerUsers", partnerUsers);
	}

	/** 美食 */
	// 获取商户类别PartnerController --- getPartnerType(t_type) 商家类型(1.宾馆 2.美食 3.娱乐)

	// 获取美食推荐--3个
	@RequestMapping("/appGetFoodTuijian")
	public Msg appGetFoodTuijian(String position_city) {
		List<PartnerUser> partnerUsers = partnerService.appGetTuijian(position_city, "2");// (1.酒店.2.美食. 3娱乐)
		return Msg.success().add("partnerUsers", partnerUsers);
	}

	// 获取商家详情PartnerController --- getPartnerUserXQ(partnerUserid)

	// 获取美食详情PartnerController --- getFoodMealXQ(m_id)

	// 查询美食列表 -后台暂无菜系对应字段
	/*
	 * position_city 所在城市 userlat 用户纬度 userlon 用户经度 t_id 商户类别表id position_area 行政区筛选
	 * praisefirst 传1为好评优先 不传为其他排序 pricesort 传1为价格从低到高 传2为价格从高到低 price_start
	 * 价格区间查询最低价 price_end 价格区间查询最高价 f_theme 主题类别
	 */
	@RequestMapping("/appGetFoodList")
	public Msg appGetFoodList(AppGetFoodEntity appGetFoodEntity) {
		PageHelper.startPage(appGetFoodEntity.getPage(), appGetFoodEntity.getRow());
		List<PartnerUser> partnerUsers = partnerService.appGetFoodList(appGetFoodEntity);
		if (partnerUsers != null && partnerUsers.size() > 0) {
			for (PartnerUser partnerUser : partnerUsers) {
				partnerUser.setJuli(LocationUtils.getDistance(appGetFoodEntity.getUserlon(), appGetFoodEntity.getUserlat(), partnerUser.getPosition_lon(), partnerUser.getPosition_lat()));
			}
		}
		return Msg.success().add("partnerUsers", new PageInfo<>(partnerUsers, 5));
	}

	/** 娱乐 */
	// 获取商户类别PartnerController --- getPartnerType(t_type) 商家类型(1.宾馆 2.美食 3.娱乐)

	// 获取娱乐项目推荐--3个
	@RequestMapping("/appGetHappyTuijian")
	public Msg appGetHappyTuijian(String position_city) {
		List<PartnerUser> partnerUsers = partnerService.appGetTuijian(position_city, "3");// (1.酒店.2.美食. 3娱乐)
		return Msg.success().add("partnerUsers", partnerUsers);
	}

	// 获取商家详情PartnerController --- getPartnerUserXQ(partnerUserid)

	// 获取娱乐项目详情PartnerController --- getHappyThemeXQ(t_id)

	// 查询娱乐列表
	@RequestMapping("/appGetHappyList")
	public Msg appGetHappyList(AppGetHappyEntity appGetHappyEntity) {

		PageHelper.startPage(appGetHappyEntity.getPage(), appGetHappyEntity.getRow());
		List<PartnerUser> partnerUsers = partnerService.appGetHappyList(appGetHappyEntity);
		if (partnerUsers != null && partnerUsers.size() > 0) {
			for (PartnerUser partnerUser : partnerUsers) {
				partnerUser.setJuli(LocationUtils.getDistance(appGetHappyEntity.getUserlon(), appGetHappyEntity.getUserlat(), partnerUser.getPosition_lon(), partnerUser.getPosition_lat()));
			}
		}
		return Msg.success().add("partnerUsers", new PageInfo<>(partnerUsers, 5));
	}
}
